import { TABS_ROUTES } from '@/store/mutation-types'
import { ITabsState } from './state'
const whiteList = ['Redirect', 'login']
export const mutations = {
  initTabs(state: ITabsState, routes) {
    state.tabsList = routes
  },
  addTabs(state: ITabsState, route): boolean {
    if (whiteList.includes(route.name)) return false
    const isExists = state.tabsList.some((item) => item.fullPath == route.fullPath)
    if (!isExists) {
      state.tabsList.push(route)
    }
    return true
  },
  closeLeftTabs(state: ITabsState, route) {
    const index = state.tabsList.findIndex((item) => item.fullPath == route.fullPath)
    state.tabsList.splice(0, index)
  },
  closeRightTabs(state: ITabsState, route) {
    const index = state.tabsList.findIndex((item) => item.fullPath == route.fullPath)
    state.tabsList.splice(index + 1)
  },
  closeOtherTabs(state: ITabsState, route) {
    state.tabsList = state.tabsList.filter((item) => item.fullPath == route.fullPath)
  }
}
